<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>
		hibernate测试
	</title>
	<script type="text/javascript" src="${pageContext.servletContext.contextPath }/js/jquery.js"></script>
</head>
<body>
	<br>
	<br>
	<form action="${pageContext.servletContext.contextPath }/addAccount" method="post">
		用户名:<input type="text" name="username"><br>
		密码:<input type="password" name="userpass"><br>
		金额:<input type="text" name="money"><br>
		<input type="submit" value="提交">
	</form>
	
	<br>
	<br>
	id号:<input type="text" name="id"><br>
	<button onclick="queryById()">查询</button>
	<br>
	<br>
	
	<table border="1">
		<thead>
			<tr>
				<th>id号</th>
				<th>用户名</th>
				<th>密码</th>
				<th>余额</th>
			</tr>
		</thead>
		<tbody id="viewInfo">
			<tr>
			
			</tr>
		</tbody>
	</table>
	<br>
	<br>
	<form action="${pageContext.servletContext.contextPath }/transferAccount" method="post">
		付款帐号:<input type="text" style="width: 150px;margin-right: 10px" name="payId">
		收款帐号:<input type="text" style="width: 150px;margin-right: 10px" name="gatherId">
		金额:<input type="text" style="width: 60px;margin-right: 10px" name="money">
		<input type="submit" value="确定">
	</form>
	
	<script type="text/javascript">
		function queryById(){
			var id = $("input[name='id']").val();
			$.ajax({
				url:'${pageContext.servletContext.contextPath }/'+id+'/getAccountById',
				type:'get',
				success:function(data){
					var dataObj = JSON.parse(data);
					$("#viewInfo").empty();
					var trObj = $("<tr></tr>");
					var idObj = $("<td>"+dataObj.id +"</td>");
					var nameObj = $("<td>"+dataObj.username +"</td>");
					var passObj = $("<td>"+dataObj.userpass +"</td>");
					var moneyObj = $("<td>"+dataObj.money +"</td>");
					trObj.append(idObj);
					trObj.append(nameObj);
					trObj.append(passObj);
					trObj.append(moneyObj);
					$("#viewInfo").append(trObj);
				}
			});
		}	
	
	
	</script>

</body>
</html>